﻿using System;

using BEGDC.CC.BL.Workflow;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.Common.Query;
using BEGDC.Utility.Castle;
using BEGDC.CC.Entity;

namespace BEGDC.CC.Web.UserControls
{
	/// <summary>
	/// Summary description for AccessControl.
	/// </summary>
	public class COAccessControl: AccessControl
	{

		public override bool IsReadOnly
		{
			get
			{
				if( base.IsReadOnly )
				{
					return base.IsReadOnly;
				}
				else
				{
					if( this._currentStep == WorkTransition.CO_CloseApp || this._currentStep == WorkTransition.CO_PSOApprove )
					{
						return true;
					}
					else
						return false;
				}
			}
		}

		public override bool IsAttachmentReadOnly
		{
			get
			{
				if(this._currentStep == WorkTransition.End && this._state!=SysDicItem.ProjectStatusFlag.Archive)
				{
					if(_state == SysDicItem.ProjectStatusFlag.Participation)
						return !this._isMgrOrStaff;
					else
						return true;
				}
				else
					return base.IsAttachmentReadOnly;
			}
		}

		public override bool IsButtonVisible(string name)
		{
			if(this.IsQuery)
			{
				switch(name)
				{
					case COTransitionList.Copy:
						return this.ShowCopyButton();
						break;
					case COTransitionList.Reply:
						return this.ShowReplyButton();
						break;
					case COTransitionList.Save:
						return this.ShowSaveButton();
						break;
					default:
						return false;
				}
			}
			else
			{
				switch(name)
				{
					case COTransitionList.Copy:
						return this.ShowCopyButton();
						break;
					case COTransitionList.Reply:
						return this.ShowReplyButton();
						break;
					default:
					switch(this._currentStep)
					{
						case WorkTransition.Draft:
							if(name == COTransitionList.Submit || name == COTransitionList.Save)
								return true;
							else
								return false;
						case WorkTransition.CO_Request:
							if(name == COTransitionList.Submit || name == COTransitionList.Save || name == COTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CO_ReRequest:
							if(name == COTransitionList.Submit || name == COTransitionList.Save)
								return true;
							else
								return false;
						case WorkTransition.CO_AssignApp:
							if(name == COTransitionList.Assign || name == COTransitionList.Reject || name == COTransitionList.Save
								|| name == COTransitionList.Check || name == COTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.CO_CheckApp:
							if(name == COTransitionList.Reject || name == COTransitionList.Check || name == COTransitionList.Query
								|| name == COTransitionList.Save)
								return true;
							else
								return false;
						case WorkTransition.CO_PSOApprove:
							if( name == COTransitionList.Reject || name == COTransitionList.Approve || name == COTransitionList.Query
								|| name == CVTransitionList.Reply)
								return true;
							else
								return false;

						case WorkTransition.CO_CloseApp:
							if( name == COTransitionList.Save || name == COTransitionList.Close)// || name == COTransitionList.Query)
								return true;
							else
								return false;
					}
						return false;
						break;
				}
			}
		}
		
	}	
}

